package com.micookie.v2ex;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.stetho.Stetho;
import com.micookie.v2ex.greendao.gen.DaoMaster;
import com.micookie.v2ex.greendao.gen.DaoSession;

/**
 * Created by Administrator on 2016/11/1.
 */

public class App extends Application {


    public static boolean IS_DEBUG = true;

    private static App AppContext;

    private DaoSession mDaoSession;


    @Override
    public void onCreate() {
        super.onCreate();
        AppContext = this;

        initDb(); //数据库初始化
        Fresco.initialize(this);//初始化Fresco图片加载
        Stetho.initializeWithDefaults(this); //初始化facebook监听插件
    }

    public static App getInstance() {
        return AppContext;
    }

    public DaoSession getDaoSession(){
        return mDaoSession;
    }

    private void initDb() {
        DaoMaster.DevOpenHelper mDbHelper = new DaoMaster.DevOpenHelper(this, "v2ex-db");
        SQLiteDatabase mDb = mDbHelper.getWritableDatabase();
        DaoMaster mDaoMaster = new DaoMaster(mDb);
        mDaoSession = mDaoMaster.newSession();

    }
}
